package com.backend.mapper;


import com.backend.pojo.entity.CourseMaterial;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.DeleteMapping;

import java.util.List;

@Mapper
public interface CourseMaterialMapper {


    /* 查询所有课程资料
     * @param courseMaterial
     * @return
     */
    List<CourseMaterial> CourseQuery(CourseMaterial courseMaterial);


    /**
     * 添加课程资料
     * @param courseMaterial
     */
    @Insert("INSERT INTO course_materials (material_name, download_url, material_description, upload_time) " +
            "VALUES (#{materialName}, #{downloadUrl}, #{materialDescription}, #{uploadTime})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    void add(CourseMaterial courseMaterial);

    /**
     * 根据id删除课程资料
     * @param id
     */
    @Delete("delete from course_materials where id = #{id} ")
    void deleteById(Integer id);

    /**
     * 修改课程资料
     * @param courseMaterial
     */
    @Update("UPDATE course_materials " +
            "SET material_name = #{materialName}, " +
            "download_url = #{downloadUrl}, " +
            "material_description = #{materialDescription}, " +
            "upload_time = #{uploadTime} " +
            "WHERE id = #{id}")
    void update(CourseMaterial courseMaterial);

    /**
     * 获取所有课程资料
     * @return
     */
    @Select("select  * from course_materials")
    List<CourseMaterial> getAll();
}